package com.ruoyi.dynamic.controller.app;


import com.ruoyi.common.core.annotation.valid.group.ValidGroup;
import com.ruoyi.common.core.constant.constant.PathConstant;
import com.ruoyi.common.core.context.SecurityContextHolder;
import com.ruoyi.common.core.pojo.vo.BaseVO;
import com.ruoyi.common.core.pojo.vo.MultiVO;
import com.ruoyi.common.core.result.Result;
import com.ruoyi.dynamic.model.pojo.entity.RoomNotice;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomNoticeAddOrEditRequest;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomNoticePushRequest;
import com.ruoyi.dynamic.service.IRoomNoticeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@Tag(name = "App-房间公告", description = "App-房间公告")
@RestController
@RequestMapping(PathConstant.APP_PATH + "room-notice")
public class AppRoomNoticeController {


    private final IRoomNoticeService iRoomNoticeService;

    public AppRoomNoticeController(IRoomNoticeService iRoomNoticeService) {
        this.iRoomNoticeService = iRoomNoticeService;
    }

    @Operation(summary = "列表", description = "列表")
    @GetMapping("listPage")
    public MultiVO<RoomNotice> listPage(Long roomId) {
        Long userId = SecurityContextHolder.getUserId();
        return Result.multi(iRoomNoticeService.listPage(roomId, userId));
    }

    @Operation(summary = "添加编辑房间公告", description = "添加编辑房间公告")
    @PostMapping("addOrEdit")
    public BaseVO addOrEdit(@RequestBody @Validated({ValidGroup.Insert.class, ValidGroup.Update.class}) AppRoomNoticeAddOrEditRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        return Result.successOrFail(iRoomNoticeService.addOrEdit(request, userId));
    }

    @Operation(summary = "删除此公告", description = "删除此公告")
    @DeleteMapping("del")
    public BaseVO del(Long id) {
        Long userId = SecurityContextHolder.getUserId();
        return Result.successOrFail(iRoomNoticeService.del(id, userId));
    }

    @Operation(summary = "发布此公告", description = "发布此公告")
    @PostMapping("publish")
    public BaseVO publish(@RequestBody @Validated(ValidGroup.Insert.class) AppRoomNoticePushRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        iRoomNoticeService.publish(request, userId);
        return Result.success();
    }

}

